package com.gexiaobao.pigeon.app.util

import android.Manifest
import android.text.TextUtils
import androidx.fragment.app.Fragment
import com.gexiaobao.pigeon.R
import com.luck.picture.lib.dialog.RemindDialog
import com.luck.picture.lib.interfaces.OnCallbackListener
import com.luck.picture.lib.interfaces.OnPermissionDeniedListener
import com.luck.picture.lib.permissions.PermissionConfig
import com.luck.picture.lib.permissions.PermissionUtil
import me.hgj.jetpackmvvm.base.appContext

/**
 * @Author      : hxw
 * @Date        : 2023/7/26 16:11
 * @Describe    :
 */
class MeOnPermissionDeniedListener : OnPermissionDeniedListener {

    override fun onDenied(
        fragment: Fragment, permissionArray: Array<String>,
        requestCode: Int, call: OnCallbackListener<Boolean>
    ) {
        var tips = ""
        tips = if (TextUtils.equals(permissionArray[0], PermissionConfig.CAMERA[0])) {
            appContext.getString(R.string.lack_of_camera_permissions)
        } else if (TextUtils.equals(permissionArray[0], Manifest.permission.RECORD_AUDIO)) {
            appContext.getString(R.string.lack_of_recording_permission)
        } else {
            appContext.getString(R.string.lack_of_storage_permission)
        }
        val dialog = RemindDialog.buildDialog(fragment.context, tips)
        dialog.setButtonText(appContext.getString(R.string.go_to_settings))
        dialog.setButtonTextColor(-0x828201)
        dialog.setContentTextColor(-0xcccccd)
        dialog.setOnDialogClickListener {
            PermissionUtil.goIntentSetting(fragment, requestCode)
            dialog.dismiss()
        }
        dialog.show()
    }
}